package com.geeka.d12.work.chatroom;

import java.io.*;
import java.net.Socket;
import java.util.ArrayList;

public class ChatThread implements Runnable{
    private Socket socket;
//    private ArrayList<Socket> sockets;
    public ChatThread( Socket socket) {
        this.socket=socket;
    }

    @Override
    public void run() {
        System.out.println("runMysocket now sockets ");

        String cname = socket.getInetAddress() + "" + socket.getPort();
        try {
            InputStream ips = socket.getInputStream();
            BufferedReader br = new BufferedReader(new InputStreamReader(ips));
            String s = null;

            OutputStream ops =socket.getOutputStream();
            PrintStream ps = new PrintStream(ops);
            ps.println();

            while ((s = br.readLine()) != null) {
                System.out.println(cname+" : "+s);
                ps.println("测试不想发回给你的消息: "+s);
//                是自己发的就不往回发其他人发的都打印出来
            }
        } catch (IOException e) {
            System.out.println(" socket异常: " + e.getMessage());
            e.printStackTrace();
        }
    }

    public void runOneSocket(Socket mysocket){


    }
    public void runMysocket(){

    }
}
